<!--
 * @Author: hucc
 * @Date: 2021-10-15 14:05:13
 * @LastEditors: hucc
 * @LastEditTime: 2021-10-15 14:41:43
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/qs.js"></script>
    <script>
        const qs = Qs;
        const baseUrl = "http://39.103.202.53:8888"
            // const loginData = {
            //         username: 'admin1',
            //         password: 123321
            //     }
        const applyData = {
                name: 'tom',
                age: 12,
                telephone: 1236668888,
                gender: 'male'
            }
            //1.实例化http请求对象
        let xhr = new XMLHttpRequest()
            //2.打开连接，设置请求的配置参数 get参数可以拼接在url后面，而且是查询字符串的格式 ? &进行拼接
            //xhr.open('post', baseUrl + '/user/login')
        xhr.open('post', baseUrl + '/user/login')
            //配置请求头的内容格式 
            //xhr.setRequestHeader('Content-Type', 'application/json')
            //发送表单数据 配置请求头格式
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        //3.发送数据并且配置请求体 post配置请求体
        //xhr.send(JSON.stringify(loginData));
        xhr.send(qs.stringify(applyData));
        //4.监听Http连接状态的改变 获取响应
        xhr.onreadystatechange = () => {
            if (xhr.readyState === 4 && xhr.status === 200) {
                console.log(JSON.parse(xhr.response));
            }
        }
    </script>
</head>

<body>

</body>

</html>